<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;

class CreateQuestionnaireValuesTable extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('questionnaire_values', function (Blueprint $table) {
            $table->id()->from(config('migration.from'));

            $table->bigInteger('field_id')->unsigned()->comment('Поле');
            $table->foreign('field_id')->references('id')->on('questionnaire_fields')->onDelete('restrict')->onUpdate('restrict');

            $table->bigInteger('response_id')->unsigned()->comment('Форма');
            $table->foreign('response_id')->references('id')->on('questionnaire_responses')->onDelete('cascade')->onUpdate('cascade');

            $table->string('person')->default(0);

            $table->jsonb('value')->default(json_encode(['']))->comment('Значения');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('questionnaire_values');
    }
}
